package classes
{
	import mx.controls.Alert;
	
	[RemoteClass(alias="classes.Page")]
	
	public class Page
	{
		public var height:int;
		public var width:int;
		
		public var layers:Array;
		
		public function Page()
		{
			layers = new Array();
		}
		
		public function AddLayer(LayerName:String):int{
			var layer:Layer = new Layer;
			layer.SetLayerName(LayerName);
			layers.push(layer);
			var returnInt:int = layers.indexOf(layer);
			
			//return the array index value
			return returnInt;
		}
		
		public function SetPageHeight(height:int):void{
			this.height = height;
		}
		
		public function GetPageHeight():int{
			return this.height;
		}
		
		public function SetPageWidth(width:int):void{
			this.width = width;
		}
		
		public function GetPageWidth():int{
			return this.width;
		}
		
		public function BuildLayersXML():XML{
			
			var pageXML:XML = 
				<page>
					<width>{this.width}</width>
					<height>{this.height}</height>
				</page>;
				
			var layersXML:XML = <layers></layers>;

			for(var counter:int; counter<this.layers.length; counter++){
				//get the item at the count point
				var layer_object:Layer = new Layer();
				layer_object = layers[counter];
				var layerXML:XML = layer_object.GetLayerXML();
				
				layersXML.appendChild(layerXML);
				  
			}
			
			pageXML.appendChild(layersXML);
			
			return pageXML;
		}
		
		public function PublicDisplayLayers():XML{
	
			var layersXML:XML = <layers></layers>;
			
			for(var counter:int; counter<this.layers.length; counter++){
				//get the item at the count point
				var layer_object:Layer = new Layer();
				layer_object = layers[counter];
				var layerXML:XML = layer_object.DisplayXML();
				
				layersXML.appendChild(layerXML);
				  
			}
			return layersXML;
		}

	}
}